package com.ccctop.cloud.handler;

import com.ccctop.cloud.service.api.TWalletService;
import com.ccctop.crowd.entity.po.TWallet;
import com.ccctop.crowd.util.ResultEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (TWallet)表控制层
 *
 * @author makejava
 * @since 2022-03-22 22:21:01
 */
@RestController
@RequestMapping("wallet")
public class TWalletController {
    /**
     * 服务对象
     */
    @Resource
    private TWalletService tWalletService;

    /**
     * 通过主键查询单条数据
     *
     *
     * @return 单条数据
     */
    @RequestMapping("/selectByUserId")
    ResultEntity<TWallet> selectWalletByUserId(@RequestParam("userId") Integer userId) {
        try{
            return ResultEntity.successWithData(this.tWalletService.queryByUserId(userId));
        }catch (Exception e){
            return ResultEntity.failed(e.getMessage());
        }
    }

    @RequestMapping("/insertWallet")
    ResultEntity<String> insertWallet(@RequestBody TWallet wallet) {
        try{
            this.tWalletService.insert(wallet);
            return ResultEntity.successWithoutData();
        }catch (Exception e){
            return ResultEntity.failed(e.getMessage());
        }
    }

}